const Shape = require("./shape.js")
const Utils = require("./utils.js")
const {EN} = require("./constant.js")

module.exports = class DrawImage extends Shape{
	constructor($env,$event){
		super($env,$event)
		this.__isInPath = false
		this.tmpCvs = Utils.createDOM("canvas")
	}
	rePaint(img){
		let ctx = this.ctx;
		let cvs = this.cvs;
		let {width,height} = Utils.domRect(img)
		let scale = 2;
		let w = width*scale
		let h = height*scale
		ctx.save()
		ctx.translate(cvs.width/2,cvs.height/2)
		ctx.drawImage(img,-w/2,-h/2,w,h)
		ctx.restore()
	}
	show(data){
		let img = data.img
		
		this.emit(EN.update_state,this,img)
		this.rePaint(img)
	}
	// show(data){
	// 	let ctx = this.tmpCvs.getContext("2d")
	// 	let image = new Image()
	// 	image.crossOrigin = "anonymous"
	// 	image.onload = function(){
	// 		ctx.drawImage(image,0,0)

	// 		let du = ctx.getImageData(0,0,100,100)
	// 		debugger
	// 	}
	// 	image.src = data.img.src
	// }
}
